package com.dries.security.core.social.config;

import lombok.Data;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/9/16 9:53
 */
@Data
public class DriesSpringSocialConfig extends SpringSocialConfigurer {

    private final String filterProcessesUrl;

    private SocialAuthFilterPostProcessor socialAuthFilterPostProcessor;

    public DriesSpringSocialConfig(String filterProcessesUrl) {
        this.filterProcessesUrl = filterProcessesUrl;
    }

    @Override
    protected <T> T postProcess(T object) {

        SocialAuthenticationFilter filter = (SocialAuthenticationFilter) super.postProcess(object);
        // 给过滤器配置自定义的filterProcessesUrl，默认为:private static final String DEFAULT_FILTER_PROCESSES_URL = "/authentication"
        filter.setFilterProcessesUrl(filterProcessesUrl);
        if (socialAuthFilterPostProcessor != null) {
            socialAuthFilterPostProcessor.process(filter);
        }
        return (T) filter;
    }
}
